﻿using Acme.ConcreteMixDesign.EntityFrameworkCore;
using Acme.ConcreteMixDesign.TopicInformations;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace Acme.ConcreteMixDesign.Repositories
{
    public class TopicInformationRepository : EfCoreRepository<ConcreteMixDesignDbContext, TopicInformation, Guid>, ITopicInformationRepository
    {
        public TopicInformationRepository(IDbContextProvider<ConcreteMixDesignDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
        /// <summary>
        /// 返回所有的答题资料
        /// </summary>
        /// <param name="ids">所有资料的Id</param>
        /// <param name="include"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        public async Task<List<TopicInformation>> GetTopicInformationByIdsAsync(List<Guid> ids, bool include, CancellationToken cancellation)
        {
            var topicInformations = (await GetDbContextAsync()).TopicInformations;
            List<TopicInformation> results = new List<TopicInformation>();
            foreach (var id in ids)
            {
                TopicInformation? result = await topicInformations
                    .FirstOrDefaultAsync
                    (x => x.Id == id
                    ,GetCancellationToken(cancellation));
                if (result != null)
                results.Add(result);
            }
            return results;
        }
    }
}
